package tests;

import org.testng.annotations.Test;
import org.apache.log4j.Logger;

import org.openqa.jetty.http.HttpRequest;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;

import util.TestCaseMessages;
import util.TestUtil;


import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;

import java.io.File;
import org.w3c.dom.*;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class xmlcheck  {
  @Test
  public void read_printxml() {
	  
	  try {
	

		  
		  DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
		  DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
		 // Document doc = docBuilder.parse (new File("D:\\09012015\\Desktop\\xml1.xml")); // normalize text representation
		  Document doc = docBuilder.parse ("http://zissit2wb01.education.vic.gov.au:8082/ZIServerAdmin/XMLMessage.aspx?RecordID=264750&MessageType=AUDITMESSAGE");
		  doc.getDocumentElement ().normalize ();
		  System.out.println ("Root element of the doc is " + doc.getDocumentElement().getNodeName());
		  
		  // to check if element exists
		  System.out.println(doc.getElementsByTagName("SchoolYear").getLength());
		  
		  // to get node value or tag value
		  
		 System.out.println(doc.getElementsByTagName("SchoolYear").item(0).getTextContent());
		 
		  // to check if element exists
		 System.out.println(doc.getElementsByTagName("SIF_EventObject").item(0).getAttributes().getLength());
		 
		  // to get node attrib value  where item(0 or 1 or 2   in reverse orcer of elements..
		 System.out.println(doc.getElementsByTagName("SIF_EventObject").item(0).getAttributes().item(1).getTextContent());
	
		//end of if clause

		 //end of for loop with s var

		  }

	  catch (SAXParseException err) {
		  System.out.println (" ** Parsing error" + ", line " + err.getLineNumber () + ", uri " + err.getSystemId ());
		  System.out.println("  "   + err.getMessage ()); }

		  catch (SAXException e) {
		  Exception x = e.getException ();
		  ((x == null) ? e : x).printStackTrace (); 
		  }
	  
	  catch (Exception e)
	  {
		 e.printStackTrace();
	  }
  }

}
